package com.example.xiaomiao.Mapper;

import com.example.xiaomiao.DO.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Select("select * from user where telephone = #{telephone}")
    User getUser(@Param("telephone") String telephone);

    @Select("select * from user where user_id = #{id}")
    User getUserById(@Param("id") int id);

    @Select("select telephone from user where user_id = #{id}")
    String getTelephone(@Param("id") int id);

    @Insert("insert into user(telephone, password, nickname) VALUES (#{user.telephone},#{user.password},#{user.nickname})")
    @Options(useGeneratedKeys = true, keyProperty = "user_id") // 自动获取主键
    void addUser(@Param("user") User user);

    void updateUser(@Param("id") int userId,@Param("user") User user);

    @Update("update user set profile_picture = #{pictureId} where user_id = #{id}")
    void updateProfilePicture(@Param("id") int userId, @Param("pictureId") int pictureId);
}
